<template>
  <div>
    <!-- 目标: 子传父 -->
    <!-- 1. 父组件, @自定义事件名="父methods函数" -->
    <MyProduct_sub
      v-for="(item, ind) in list"
      :key="item.id"
      :title="item.proname"
      :price="item.proprice"
      :intro="item.info"
      :index="ind"
      @subFn="fn"
    ></MyProduct_sub>
  </div>
</template>

<script>
import MyProduct_sub from "./components/MyProduct_sub.vue";
export default {
  components: { MyProduct_sub },
  data() {
    return {
      list: [
        {
          id: 1,
          proname: "超级好吃的棒棒糖",
          proprice: 18.8,
          info: "开业大酬宾, 全场8折",
        },
        {
          id: 2,
          proname: "超级好吃的大鸡腿",
          proprice: 34.2,
          info: "好吃不腻, 快来买啊",
        },
        {
          id: 3,
          proname: "超级无敌的冰激凌",
          proprice: 14.2,
          info: "炎热的夏天, 来个冰激凌了",
        },
      ],
    };
  },
  methods: {
    fn(index, price) {
      // 逻辑代码
      this.list[index].proprice > 1 &&
        (this.list[index].proprice -= price.toFixed(2));
    },
  },
};
</script>

<style>
</style>